
#include <BFont>
#include <BStyle>
#include <BWidget>
#include "member_BCheckBox.h"

using namespace BWE;

member_BCheckBox::member_BCheckBox(BCheckBox* checkBox)
{
	boss = checkBox;
	align = Align_Left | Align_VCenter;
	checked = false;
	hoverImage = false;
	state = State_Normal;
	space = 3;
	dirty = true;
}
member_BCheckBox::~member_BCheckBox()
{

}

void member_BCheckBox::freshRects()
{
	const BStyle* style = boss->realStyle();
	t_text.clear();
	if (text.size() && style)
		style->trans(text, t_text);
	else
		t_text.clear();

	const BFont* font = boss->font();
	if (font)
	{
		if (t_text.size())
			textSize = font->textSize(t_text);
		else
			textSize = font->textSize(text);
	}

	BRect crect = boss->clientRect();

	BSize realIconSize;
	realIconSize = iconSize;
	if (realIconSize.width() < 1)
		realIconSize.width() = textSize.height();
	if (realIconSize.height() < 1)
		realIconSize.height() = textSize.height();
	realIconSize.wrap(crect.size());

	iconRect = crect.align(align, realIconSize);
	BRect textArea;
	if (align & Align_Right)
	{
		textArea.left() = crect.left();
		textArea.top() = crect.top();
		textArea.right() = iconRect.left() - space;
		textArea.bottom() = crect.bottom();
	}
	else
	{
		textArea.left() = iconRect.right() + space;
		textArea.top() = crect.top();
		textArea.right() = crect.right();
		textArea.bottom() = crect.bottom();
	}
	textRect = textArea.align(align, textSize);
}
